package com.treasure.infrastructure.domain.llm.qianwen.client;

import com.alibaba.dashscope.embeddings.TextEmbedding;
import com.alibaba.dashscope.embeddings.TextEmbeddingParam;
import com.alibaba.dashscope.embeddings.TextEmbeddingResult;
import com.alibaba.dashscope.embeddings.TextEmbeddingResultItem;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sunhongmin
 * @date 2023/8/25 17:51
 * @description
 */
@Service
public class QwenEmbeddingVectorClient extends QwenContext {

    public List<TextEmbeddingResultItem> textEmbeddingVector(List<String> segmentTextList) throws NoApiKeyException {
        Constants.apiKey = qwenConfigBean.getKey();
        TextEmbeddingParam param = TextEmbeddingParam
                .builder()
                .model(qwenConfigBean.getTextEmbedding())
                .texts(segmentTextList)
                .build();
        TextEmbedding textEmbedding = new TextEmbedding();
        TextEmbeddingResult result = textEmbedding.call(param);
        return result.getOutput().getEmbeddings();
    }

}
